/*
 *  SPAGL Copyright (C) 2008 Sam Pottinger
 *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
 *  General Public License as published by the Free Software Foundation; either version 2.1 of the License, or 
 *  (at your option) any later version. This library is distributed in the hope that it will be useful, but 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *  See the GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License along with this library; if not, 
 *  write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */

package spagswing;

import java.awt.Component;
import java.awt.Container;
import net.miginfocom.swing.MigLayout;
import spagcore.SpaglCoreContainer;
import spagcore.SpaglCoreWidget;

/**
 * A Container (java.awt.Container) that conforms to the SpaglCoreContainer interface
 * @author Sam Pottinger
 */
public class SpaglContainer extends Container implements SpaglCoreContainer, SpaglCoreWidget {

	private static final long serialVersionUID = 1L;
	private MigLayout layoutManager = new MigLayout();
	private SpaglContainer parent;
	
	/**
	 * Creates a bare bones container
	 * 
	 * @param newParent the {@link SpaglContainer} that will be the parent of this widget
	 */
	public SpaglContainer(SpaglContainer newParent)
	{
		super();
		super.setLayout(layoutManager);
		parent = newParent;
	}
	
	/**
	 * Creates a container with specified parameters for the layout manager
	 * @param newParent the {@link SpaglContainer} to be the parent of this widget
	 * @param placementParam The parameters to passed to the layout manager
	 */
	public SpaglContainer(SpaglContainer newParent, String placementParam)
	{
		super();
		super.setLayout(layoutManager);
		parent = newParent;
		parent.placeWidget(this, placementParam);
	}
	
	/**
	 * Creates a container with the specified layout manager parameters and layout manager
	 * @param newParent The parent of this widget
	 * @param placementParam The parameters passed to the layout manager
	 * @param newLayoutManager A (at this moment in development) MigLayout object
	 */
	public SpaglContainer(SpaglContainer newParent, String placementParam, MigLayout newLayoutManager)
	{
		super();
		layoutManager = newLayoutManager;
		super.setLayout(layoutManager);
		parent = newParent;
		parent.placeWidget(this, placementParam);
	}

	/**
	 * Places a widget on this container with the given string parameters
	 * @param w the target widget to be placed in this container
	 * @param param the string parameters for the layout manager
	 */
	public void placeWidget(SpaglCoreWidget w, String param) {
		
		super.add((Component) w, param);
		
	}

	/**
	 * Gets the parent container for this widget
	 * 
	 * @return Returns the {@link SpaglContainer} that is the holding this widget
	 */
	public SpaglCoreContainer getContainer() {
		return this;
	}
	
	/**
	 * Swing does not need manual disposal, so this is here just for cross library purposes
	 */ 
	public void dispose() {}

}
